﻿using System.Web;
using System.Data;
using System.Linq;
using APH.Parl2.Client.Internet.MVC.Parl2DataServiceReference;
using System.Configuration;

namespace APH.Parl2.Client.Internet.MVC.Models
{

    public class ParliamentarianRepository : IParliamentarianRepository
    {
        static System.Uri serviceUri = new System.Uri(ConfigurationManager.AppSettings["ServiceUri"]);
        Parl2Container parl2Container = null;

        public ParliamentarianRepository()
        {
            parl2Container = new Parl2DataServiceReference.Parl2Container(serviceUri);        
        }
        

        //
        // Query Methods

     
        public IQueryable<Parliamentarian> FindAllParliamentarians()
        {
            return parl2Container.Parliamentarians;
        }


        public IQueryable<Parliamentarian> FindByElectorate(string electorate)
        {
            var parlObjs = from parliamentarian in FindAllParliamentarians()
                                  where parliamentarian.Electorate == electorate
                                  select parliamentarian;
            return parlObjs;
        }

        public Parliamentarian GetParliamentarian(int id)
        {

            return parl2Container.Parliamentarians.Where(p => p.CPALId == id).First();
        }

        
        

       
    }
}
